package world;

import java.util.ArrayList;

import game.Game;

import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class World extends BasicGameState {

	Animation token, movingUp, movingDown, movingLeft, movingRight;
	static Image worldMap, town, crosshair;
	static EventStore stores;
	static Player player;
	static boolean debug = false;

	static boolean quit = false;
	public static float viewX = 0;
	public static float viewY = 0;
	InputHandler input;

public World (int state){}
	
	@Override
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{

		input = new InputHandler();
		worldMap = new Image("res/world/world.png");
		crosshair = new Image("res/world/crosshair.png");
		stores = new EventStore();
		
		player = new Player(stores.getEvents().get(0));
	
		centerView();
	}
	
@Override
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{

//draws world map image	
worldMap.draw(viewX, viewY);
//draws event images and paths between images	
stores.renderEventLocations(g, viewX, viewY);
//draws the image for the party's location.
Player.renderPlayer(viewX, viewY);
   
if(!Pathing.run){crosshair.draw(Game.WIDTH /2 - crosshair.getWidth()/2, Game.HEIGHT/2 - crosshair.getHeight()/2);}

//toggle draw x and y if user pressed f1
debugHud(g);

//temp menu
	if(quit==true){
		g.drawString("Resume (R)", 250, 100);
		g.drawString("Main Menu (M)", 250, 150);
		g.drawString("Quit (Q)", 250, 200);
		if(quit==false){g.clear();}
	}
}
	
	@Override
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
	input.world(gc.getInput(), delta, sbg);		
}
	
@Override
public int getID() {return 1;}

public static void centerView(){
	
	int destX =  (int)Player.x;
	int destY = (int)Player.y;

	viewX =   (destX - destX*2) + (Game.WIDTH/2);
	viewY =   (destY - destY*2) + (Game.HEIGHT/2);
	
}
		

private void debugHud(Graphics g){
	if(debug){
	int posX = Mouse.getX();
	int posY = Mouse.getY();
	g.drawString("Cam's X: " + (int)viewX + "\nCam's Y: " + (int)viewY, Game.WIDTH - 150, 20);
	g.drawString("M X:" + posX + " Y:" + posY, Game.WIDTH - 150, 75);
	g.drawString("place X: " + Math.abs((int)viewX - Game.WIDTH/2) + "\nplace Y: " + Math.abs((int)viewY - Game.HEIGHT/2), Game.WIDTH - 150, 100);
		}
		
	}
	

}
